<?php
	session_start();

	//restrict page access
	if(!isset($_SESSION['user']))
	{
		header('Location:index.php');
		exit;
	}

	include("std_dbs.php");
	$title = "My Activities";
	include('header.php');


?>
	
<!-- start content -->
	<div id="content">
		<div class="post">
			<h1 class="title"><a href="#">My Activities</a></h1>
			<div class="entry">
				<font color='red'><?php echo $_COOKIE['logMessage'] . "<br />"; setcookie("logMessage", "", time()-3600); ?></font>
				<form name='logSort' method='post' action='mylog.php'>
				Sort by: <input type='radio' name='searchType' value='LOGDATE' checked>Date 
				<input type='radio' name='searchType' value='ACTION'>Action
				<br /><input type='submit' value='Display' name='submit'>
				</form>		
			</div>
		</div>

		<?php

//		if(isset($_POST['submit']))
//		{
			$searchType = addslashes($_POST['searchType']);
			$userId = $_SESSION['userid'];

			if(empty($searchType))
				$searchType = "LOGDATE";

			//build query
                	$query ="SELECT * FROM UserLog WHERE USERID = '".$userId."' ORDER BY $searchType DESC";

                	//Prepare and execute query
                	$stid = oci_parse($connect, $query);
                	oci_execute($stid); // or die(oci_error($stid));		

			// Fetch results
			$nrows = oci_fetch_all($stid, $results);

			//Display results
			echo "<table width='90%'><tr style='font-weight:bold;'><td>Log ID</td><td>Log Date</td><td>Action</td><td>IP Address</td></tr>";
			for($i = 0; $i<$nrows; $i++)
			{
				//pull info from database
				$logId = $results['LOGID'][$i];
				$userId = $results['USERID'][$i];
				$logDate = $results['LOGDATE'][$i];
				$action = $results['ACTION'][$i];
				$ipAddress = $results['IPADDRESS'][$i];
				
				//echo info into a table
				echo "<tr><td>$logId $userId</td><td>$logDate</td><td>$action</td><td>$ipAddress</td></tr>";
			}
			echo "</table>";
//		}
		?>
	</div>
<!-- end content -->

<?php include('footer.php'); ?>
